import Vue from 'vue';
import Vuex from 'vuex';

import { CHANGE_NAME } from './types';

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    message: '',
    say: 'Hello',
  },
  mutations: {
    [CHANGE_NAME](state, payload) {
      state.message = payload.message;
      state.say = `${payload.message} ${payload.name}`;
    },
    changeMessage(state, payload) {
      state.message = payload.message;
    },
  },
  actions: {
    sayHello(context, payload) {
      // context.dispatch('findName');
      // context.commit('changeMessage', payload);
      context.commit(CHANGE_NAME, payload);
    },
    findName() {

    },
  },
});
